package com.itheima.java.ai.langchin4j.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.java.ai.langchin4j.entity.Appointment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface AppointmentMapper extends BaseMapper<Appointment> {
    
    @Select("SELECT * FROM appointments WHERE user_id = #{userId} ORDER BY appointment_date DESC, time_slot")
    List<Appointment> findByUserId(Long userId);
    
    @Select("SELECT * FROM appointments WHERE doctor_id = #{doctorId} ORDER BY appointment_date DESC, time_slot")
    List<Appointment> findByDoctorId(Long doctorId);
    
    @Select("SELECT * FROM appointments WHERE user_id = #{userId} AND status = #{status} ORDER BY appointment_date DESC")
    List<Appointment> findByUserIdAndStatus(Long userId, String status);
    
    @Select("SELECT * FROM appointments WHERE doctor_id = #{doctorId} AND appointment_date = #{date} ORDER BY time_slot")
    List<Appointment> findByDoctorIdAndDate(Long doctorId, LocalDate date);
    
    @Update("UPDATE appointments SET status = #{status} WHERE id = #{appointmentId}")
    int updateStatus(Long appointmentId, String status);
}